package com.xiaotao.controller;

import com.xiaotao.entity.Goods;
import com.xiaotao.service.GoodsService;
import com.xiaotao.util.ResponseUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
@Api(tags = "商品相关")
@RestController
@RequestMapping("goods")
public class GoodsController {
    @Resource
    private GoodsService goodsService;
    //查询全部商品信息
    @ApiOperation(value = "查询全部商品信息")
    @GetMapping("{pageNum}/{pageSize}")
    public ResponseUtil list(@PathVariable Integer pageNum, @PathVariable Integer pageSize){
        return goodsService.findAll(pageNum,pageSize);
    }
    //根据商户id查询商品信息
    @ApiOperation(value = "根据商户查询商品信息")
    @GetMapping("/merchant/{merchantId}")
    public ResponseUtil findByMerchantId(@PathVariable Integer merchantId){
        return goodsService.findByMerchantId(merchantId);
    }

    //根据id查询商品信息
    @ApiOperation(value = "根据id商品信息")
    @GetMapping("{id}")
    public ResponseUtil findById(@PathVariable Integer id){
        return goodsService.findById(id);
    }

    //添加商品
    @ApiOperation(value = "添加商品")
    @PostMapping
    public ResponseUtil save(@RequestBody Goods goods){
        return goodsService.save(goods);
    }
    //修改商品
    @ApiOperation(value = "修改商品")
    @PutMapping
    public ResponseUtil update(@RequestBody Goods goods){
        return goodsService.update(goods);
    }
    //删除商品
    @ApiOperation(value = "删除商品")
    @DeleteMapping("{id}")
    public ResponseUtil delete(@PathVariable Integer id){
        return goodsService.delete(id);
    }
}
